<?php
/**
 * Created by PhpStorm.
 * Author: 黑瞎子
 * Date: 2018/3/20
 * Time: 10:06
 */

namespace app\api\model;


class Order extends BaseModel
{
    protected $hidden = ['user_id', 'delete_time', 'update_time'];
    //开启模型写入数据库时的自动记录写入时间
    protected $autoWriteTimestamp = true;

    public function getSnapItemsAttr($value){
        if (empty($value)){
            return null;
        }
        return json_decode($value);
    }

    public function getSnapAddressAttr($value){
        if (empty($value)){
            return null;
        }
        return json_decode($value);
    }

    //获取用户历史订单分页数据
    public static function getSummaryByUser($uid, $page = 1, $size = 15){
        $pagingDate = self::where('user_id', '=', $uid)
            ->order('create_time desc')
            ->paginate($size, true, ['page' => $page]);
        return $pagingDate;
    }

    //CMS 获取订单数据 (分页)
    public static function getSummaryByPage($page = 1, $size = 20){
        $pagingDate = self::order('create_time desc')
            ->paginate($size, true, ['page' => $page]);
        return $pagingDate;
    }
}